//
//  HHUpDownTextView.m
//  Smart
//
//  Created by Hayder on 2022/12/22.
//

#import "HHUpDownTextView.h"
#import "HHGlobalDefine.h"

@interface HHUpDownTextView()

@property (nonatomic, strong) UIControl *control;

@end

@implementation HHUpDownTextView

- (instancetype)initWithFrame:(CGRect)frame
                       upText:(NSString *)upText upFont:(UIFont *)upFont upFontColor:(UIColor *)color
                     downText:(NSString *)downText downFont:(UIFont *)downFont dwonFontColor:(UIColor *)downColor
                    lineSpace:(CGFloat)space
{
    if (self = [super initWithFrame:frame]) {
        
        self.upLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.width, upFont.lineHeight)];
        self.upLabel.textColor = color;
        self.upLabel.font = upFont;
        self.upLabel.textAlignment = NSTextAlignmentCenter;
        self.upLabel.text = upText;
        [self addSubview:self.upLabel];
        
        self.downLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.height - downFont.lineHeight, self.width, downFont.lineHeight)];
        self.downLabel.textColor = downColor;
        self.downLabel.font = downFont;
        self.downLabel.text = downText;
        self.downLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.downLabel];
        
        self.upLabel.y = (self.height - space)/2 - self.upLabel.height;
        self.downLabel.y = (self.height + space)/2;
        
        UIControl *control = [[UIControl alloc] initWithFrame:self.bounds];
        [control addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:control];
    }
    
    return self;
}

- (void)clickEvent:(UIControl *)sender
{
    if (self.clickBlock) {
        self.clickBlock();
    }
}

@end
